package dao;


import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.TorqueException;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;

  
  
/**
 * This class was autogenerated by Torque on:
 *
 * [Fri Jan 09 02:39:32 PST 2009]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to Unit
 */
public abstract class BaseUnit extends BaseObject
{
    /** The Peer class */
    private static final UnitPeer peer =
        new UnitPeer();

        
    /** The value for the unitid field */
    private int unitid;
      
    /** The value for the unitcode field */
    private String unitcode;
      
    /** The value for the unitname field */
    private String unitname;
      
    /** The value for the unittype field */
    private String unittype;
      
    /** The value for the collegeid field */
    private int collegeid;
  
    
    /**
     * Get the Unitid
     *
     * @return int
     */
    public int getUnitid()
    {
        return unitid;
    }

                                              
    /**
     * Set the value of Unitid
     *
     * @param v new value
     */
    public void setUnitid(int v) throws TorqueException
    {
    
                  if (this.unitid != v)
              {
            this.unitid = v;
            setModified(true);
        }
    
          
                                  
        // update associated DegreeCourse
        if (collDegreeCourses != null)
        {
            for (int i = 0; i < collDegreeCourses.size(); i++)
            {
                ((DegreeCourse) collDegreeCourses.get(i))
                    .setUnitid(v);
            }
        }
                                          
        // update associated DegreeCurriculum
        if (collDegreeCurriculums != null)
        {
            for (int i = 0; i < collDegreeCurriculums.size(); i++)
            {
                ((DegreeCurriculum) collDegreeCurriculums.get(i))
                    .setUnitid(v);
            }
        }
                                          
        // update associated CourseOfferingUnit
        if (collCourseOfferingUnits != null)
        {
            for (int i = 0; i < collCourseOfferingUnits.size(); i++)
            {
                ((CourseOfferingUnit) collCourseOfferingUnits.get(i))
                    .setUnitid(v);
            }
        }
                                          
        // update associated Classroom
        if (collClassrooms != null)
        {
            for (int i = 0; i < collClassrooms.size(); i++)
            {
                ((Classroom) collClassrooms.get(i))
                    .setUnitid(v);
            }
        }
                                          
        // update associated EmployeeUnit
        if (collEmployeeUnits != null)
        {
            for (int i = 0; i < collEmployeeUnits.size(); i++)
            {
                ((EmployeeUnit) collEmployeeUnits.get(i))
                    .setUnitid(v);
            }
        }
                      }
  
    /**
     * Get the Unitcode
     *
     * @return String
     */
    public String getUnitcode()
    {
        return unitcode;
    }

                        
    /**
     * Set the value of Unitcode
     *
     * @param v new value
     */
    public void setUnitcode(String v) 
    {
    
                  if (!ObjectUtils.equals(this.unitcode, v))
              {
            this.unitcode = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Unitname
     *
     * @return String
     */
    public String getUnitname()
    {
        return unitname;
    }

                        
    /**
     * Set the value of Unitname
     *
     * @param v new value
     */
    public void setUnitname(String v) 
    {
    
                  if (!ObjectUtils.equals(this.unitname, v))
              {
            this.unitname = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Unittype
     *
     * @return String
     */
    public String getUnittype()
    {
        return unittype;
    }

                        
    /**
     * Set the value of Unittype
     *
     * @param v new value
     */
    public void setUnittype(String v) 
    {
    
                  if (!ObjectUtils.equals(this.unittype, v))
              {
            this.unittype = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Collegeid
     *
     * @return int
     */
    public int getCollegeid()
    {
        return collegeid;
    }

                              
    /**
     * Set the value of Collegeid
     *
     * @param v new value
     */
    public void setCollegeid(int v) throws TorqueException
    {
    
                  if (this.collegeid != v)
              {
            this.collegeid = v;
            setModified(true);
        }
    
                          
                if (aCollege != null && !(aCollege.getCollegeid() == v))
                {
            aCollege = null;
        }
      
              }
  
      
    
                  
    
        private College aCollege;

    /**
     * Declares an association between this object and a College object
     *
     * @param v College
     * @throws TorqueException
     */
    public void setCollege(College v) throws TorqueException
    {
            if (v == null)
        {
                    setCollegeid(0);
                  }
        else
        {
            setCollegeid(v.getCollegeid());
        }
                aCollege = v;
    }

                                            
    /**
     * Get the associated College object
     *
     * @return the associated College object
     * @throws TorqueException
     */
    public College getCollege() throws TorqueException
    {
        if (aCollege == null && (this.collegeid > 0))
        {
                          aCollege = CollegePeer.retrieveByPK(SimpleKey.keyFor(this.collegeid));
              
            /* The following can be used instead of the line above to
               guarantee the related object contains a reference
               to this object, but this level of coupling
               may be undesirable in many circumstances.
               As it can lead to a db query with many results that may
               never be used.
               College obj = CollegePeer.retrieveByPK(this.collegeid);
               obj.addUnits(this);
            */
        }
        return aCollege;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey.  e.g.
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
           */
    public void setCollegeKey(ObjectKey key) throws TorqueException
    {
      
                        setCollegeid(((NumberKey) key).intValue());
                  }
       
                                
            
    /**
     * Collection to store aggregation of collDegreeCourses
     */
    protected List collDegreeCourses;

    /**
     * Temporary storage of collDegreeCourses to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initDegreeCourses()
    {
        if (collDegreeCourses == null)
        {
            collDegreeCourses = new ArrayList();
        }
    }

    /**
     * Method called to associate a DegreeCourse object to this object
     * through the DegreeCourse foreign key attribute
     *
     * @param l DegreeCourse
     * @throws TorqueException
     */
    public void addDegreeCourse(DegreeCourse l) throws TorqueException
    {
        getDegreeCourses().add(l);
        l.setUnit((Unit) this);
    }

    /**
     * The criteria used to select the current contents of collDegreeCourses
     */
    private Criteria lastDegreeCoursesCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getDegreeCourses(new Criteria())
     *
     * @throws TorqueException
     */
    public List getDegreeCourses() throws TorqueException
    {
        if (collDegreeCourses == null)
        {
            collDegreeCourses = getDegreeCourses(new Criteria(10));
        }
        return collDegreeCourses;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Unit has previously
     * been saved, it will retrieve related DegreeCourses from storage.
     * If this Unit is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getDegreeCourses(Criteria criteria) throws TorqueException
    {
        if (collDegreeCourses == null)
        {
            if (isNew())
            {
               collDegreeCourses = new ArrayList();
            }
            else
            {
                      criteria.add(DegreeCoursePeer.UNITID, getUnitid() );
                      collDegreeCourses = DegreeCoursePeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(DegreeCoursePeer.UNITID, getUnitid());
                      if (!lastDegreeCoursesCriteria.equals(criteria))
                {
                    collDegreeCourses = DegreeCoursePeer.doSelect(criteria);
                }
            }
        }
        lastDegreeCoursesCriteria = criteria;

        return collDegreeCourses;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getDegreeCourses(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getDegreeCourses(Connection con) throws TorqueException
    {
        if (collDegreeCourses == null)
        {
            collDegreeCourses = getDegreeCourses(new Criteria(10), con);
        }
        return collDegreeCourses;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Unit has previously
     * been saved, it will retrieve related DegreeCourses from storage.
     * If this Unit is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getDegreeCourses(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collDegreeCourses == null)
        {
            if (isNew())
            {
               collDegreeCourses = new ArrayList();
            }
            else
            {
                       criteria.add(DegreeCoursePeer.UNITID, getUnitid());
                       collDegreeCourses = DegreeCoursePeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(DegreeCoursePeer.UNITID, getUnitid());
                       if (!lastDegreeCoursesCriteria.equals(criteria))
                 {
                     collDegreeCourses = DegreeCoursePeer.doSelect(criteria, con);
                 }
             }
         }
         lastDegreeCoursesCriteria = criteria;

         return collDegreeCourses;
     }

                  
              
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Unit is new, it will return
     * an empty collection; or if this Unit has previously
     * been saved, it will retrieve related DegreeCourses from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Unit.
     */
    protected List getDegreeCoursesJoinUnit(Criteria criteria)
        throws TorqueException
    {
        if (collDegreeCourses == null)
        {
            if (isNew())
            {
               collDegreeCourses = new ArrayList();
            }
            else
            {
                            criteria.add(DegreeCoursePeer.UNITID, getUnitid());
                            collDegreeCourses = DegreeCoursePeer.doSelectJoinUnit(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(DegreeCoursePeer.UNITID, getUnitid());
                        if (!lastDegreeCoursesCriteria.equals(criteria))
            {
                collDegreeCourses = DegreeCoursePeer.doSelectJoinUnit(criteria);
            }
        }
        lastDegreeCoursesCriteria = criteria;

        return collDegreeCourses;
    }
                            


                          
            
    /**
     * Collection to store aggregation of collDegreeCurriculums
     */
    protected List collDegreeCurriculums;

    /**
     * Temporary storage of collDegreeCurriculums to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initDegreeCurriculums()
    {
        if (collDegreeCurriculums == null)
        {
            collDegreeCurriculums = new ArrayList();
        }
    }

    /**
     * Method called to associate a DegreeCurriculum object to this object
     * through the DegreeCurriculum foreign key attribute
     *
     * @param l DegreeCurriculum
     * @throws TorqueException
     */
    public void addDegreeCurriculum(DegreeCurriculum l) throws TorqueException
    {
        getDegreeCurriculums().add(l);
        l.setUnit((Unit) this);
    }

    /**
     * The criteria used to select the current contents of collDegreeCurriculums
     */
    private Criteria lastDegreeCurriculumsCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getDegreeCurriculums(new Criteria())
     *
     * @throws TorqueException
     */
    public List getDegreeCurriculums() throws TorqueException
    {
        if (collDegreeCurriculums == null)
        {
            collDegreeCurriculums = getDegreeCurriculums(new Criteria(10));
        }
        return collDegreeCurriculums;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Unit has previously
     * been saved, it will retrieve related DegreeCurriculums from storage.
     * If this Unit is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getDegreeCurriculums(Criteria criteria) throws TorqueException
    {
        if (collDegreeCurriculums == null)
        {
            if (isNew())
            {
               collDegreeCurriculums = new ArrayList();
            }
            else
            {
                      criteria.add(DegreeCurriculumPeer.UNITID, getUnitid() );
                      collDegreeCurriculums = DegreeCurriculumPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(DegreeCurriculumPeer.UNITID, getUnitid());
                      if (!lastDegreeCurriculumsCriteria.equals(criteria))
                {
                    collDegreeCurriculums = DegreeCurriculumPeer.doSelect(criteria);
                }
            }
        }
        lastDegreeCurriculumsCriteria = criteria;

        return collDegreeCurriculums;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getDegreeCurriculums(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getDegreeCurriculums(Connection con) throws TorqueException
    {
        if (collDegreeCurriculums == null)
        {
            collDegreeCurriculums = getDegreeCurriculums(new Criteria(10), con);
        }
        return collDegreeCurriculums;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Unit has previously
     * been saved, it will retrieve related DegreeCurriculums from storage.
     * If this Unit is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getDegreeCurriculums(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collDegreeCurriculums == null)
        {
            if (isNew())
            {
               collDegreeCurriculums = new ArrayList();
            }
            else
            {
                       criteria.add(DegreeCurriculumPeer.UNITID, getUnitid());
                       collDegreeCurriculums = DegreeCurriculumPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(DegreeCurriculumPeer.UNITID, getUnitid());
                       if (!lastDegreeCurriculumsCriteria.equals(criteria))
                 {
                     collDegreeCurriculums = DegreeCurriculumPeer.doSelect(criteria, con);
                 }
             }
         }
         lastDegreeCurriculumsCriteria = criteria;

         return collDegreeCurriculums;
     }

                        
              
                    
                    
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Unit is new, it will return
     * an empty collection; or if this Unit has previously
     * been saved, it will retrieve related DegreeCurriculums from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Unit.
     */
    protected List getDegreeCurriculumsJoinCurriculum(Criteria criteria)
        throws TorqueException
    {
        if (collDegreeCurriculums == null)
        {
            if (isNew())
            {
               collDegreeCurriculums = new ArrayList();
            }
            else
            {
                            criteria.add(DegreeCurriculumPeer.UNITID, getUnitid());
                            collDegreeCurriculums = DegreeCurriculumPeer.doSelectJoinCurriculum(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(DegreeCurriculumPeer.UNITID, getUnitid());
                        if (!lastDegreeCurriculumsCriteria.equals(criteria))
            {
                collDegreeCurriculums = DegreeCurriculumPeer.doSelectJoinCurriculum(criteria);
            }
        }
        lastDegreeCurriculumsCriteria = criteria;

        return collDegreeCurriculums;
    }
                  
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Unit is new, it will return
     * an empty collection; or if this Unit has previously
     * been saved, it will retrieve related DegreeCurriculums from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Unit.
     */
    protected List getDegreeCurriculumsJoinUnit(Criteria criteria)
        throws TorqueException
    {
        if (collDegreeCurriculums == null)
        {
            if (isNew())
            {
               collDegreeCurriculums = new ArrayList();
            }
            else
            {
                            criteria.add(DegreeCurriculumPeer.UNITID, getUnitid());
                            collDegreeCurriculums = DegreeCurriculumPeer.doSelectJoinUnit(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(DegreeCurriculumPeer.UNITID, getUnitid());
                        if (!lastDegreeCurriculumsCriteria.equals(criteria))
            {
                collDegreeCurriculums = DegreeCurriculumPeer.doSelectJoinUnit(criteria);
            }
        }
        lastDegreeCurriculumsCriteria = criteria;

        return collDegreeCurriculums;
    }
                            


                          
            
    /**
     * Collection to store aggregation of collCourseOfferingUnits
     */
    protected List collCourseOfferingUnits;

    /**
     * Temporary storage of collCourseOfferingUnits to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initCourseOfferingUnits()
    {
        if (collCourseOfferingUnits == null)
        {
            collCourseOfferingUnits = new ArrayList();
        }
    }

    /**
     * Method called to associate a CourseOfferingUnit object to this object
     * through the CourseOfferingUnit foreign key attribute
     *
     * @param l CourseOfferingUnit
     * @throws TorqueException
     */
    public void addCourseOfferingUnit(CourseOfferingUnit l) throws TorqueException
    {
        getCourseOfferingUnits().add(l);
        l.setUnit((Unit) this);
    }

    /**
     * The criteria used to select the current contents of collCourseOfferingUnits
     */
    private Criteria lastCourseOfferingUnitsCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getCourseOfferingUnits(new Criteria())
     *
     * @throws TorqueException
     */
    public List getCourseOfferingUnits() throws TorqueException
    {
        if (collCourseOfferingUnits == null)
        {
            collCourseOfferingUnits = getCourseOfferingUnits(new Criteria(10));
        }
        return collCourseOfferingUnits;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Unit has previously
     * been saved, it will retrieve related CourseOfferingUnits from storage.
     * If this Unit is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getCourseOfferingUnits(Criteria criteria) throws TorqueException
    {
        if (collCourseOfferingUnits == null)
        {
            if (isNew())
            {
               collCourseOfferingUnits = new ArrayList();
            }
            else
            {
                      criteria.add(CourseOfferingUnitPeer.UNITID, getUnitid() );
                      collCourseOfferingUnits = CourseOfferingUnitPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(CourseOfferingUnitPeer.UNITID, getUnitid());
                      if (!lastCourseOfferingUnitsCriteria.equals(criteria))
                {
                    collCourseOfferingUnits = CourseOfferingUnitPeer.doSelect(criteria);
                }
            }
        }
        lastCourseOfferingUnitsCriteria = criteria;

        return collCourseOfferingUnits;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getCourseOfferingUnits(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getCourseOfferingUnits(Connection con) throws TorqueException
    {
        if (collCourseOfferingUnits == null)
        {
            collCourseOfferingUnits = getCourseOfferingUnits(new Criteria(10), con);
        }
        return collCourseOfferingUnits;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Unit has previously
     * been saved, it will retrieve related CourseOfferingUnits from storage.
     * If this Unit is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getCourseOfferingUnits(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collCourseOfferingUnits == null)
        {
            if (isNew())
            {
               collCourseOfferingUnits = new ArrayList();
            }
            else
            {
                       criteria.add(CourseOfferingUnitPeer.UNITID, getUnitid());
                       collCourseOfferingUnits = CourseOfferingUnitPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(CourseOfferingUnitPeer.UNITID, getUnitid());
                       if (!lastCourseOfferingUnitsCriteria.equals(criteria))
                 {
                     collCourseOfferingUnits = CourseOfferingUnitPeer.doSelect(criteria, con);
                 }
             }
         }
         lastCourseOfferingUnitsCriteria = criteria;

         return collCourseOfferingUnits;
     }

                        
              
                    
                    
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Unit is new, it will return
     * an empty collection; or if this Unit has previously
     * been saved, it will retrieve related CourseOfferingUnits from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Unit.
     */
    protected List getCourseOfferingUnitsJoinCourse(Criteria criteria)
        throws TorqueException
    {
        if (collCourseOfferingUnits == null)
        {
            if (isNew())
            {
               collCourseOfferingUnits = new ArrayList();
            }
            else
            {
                            criteria.add(CourseOfferingUnitPeer.UNITID, getUnitid());
                            collCourseOfferingUnits = CourseOfferingUnitPeer.doSelectJoinCourse(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(CourseOfferingUnitPeer.UNITID, getUnitid());
                        if (!lastCourseOfferingUnitsCriteria.equals(criteria))
            {
                collCourseOfferingUnits = CourseOfferingUnitPeer.doSelectJoinCourse(criteria);
            }
        }
        lastCourseOfferingUnitsCriteria = criteria;

        return collCourseOfferingUnits;
    }
                  
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Unit is new, it will return
     * an empty collection; or if this Unit has previously
     * been saved, it will retrieve related CourseOfferingUnits from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Unit.
     */
    protected List getCourseOfferingUnitsJoinUnit(Criteria criteria)
        throws TorqueException
    {
        if (collCourseOfferingUnits == null)
        {
            if (isNew())
            {
               collCourseOfferingUnits = new ArrayList();
            }
            else
            {
                            criteria.add(CourseOfferingUnitPeer.UNITID, getUnitid());
                            collCourseOfferingUnits = CourseOfferingUnitPeer.doSelectJoinUnit(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(CourseOfferingUnitPeer.UNITID, getUnitid());
                        if (!lastCourseOfferingUnitsCriteria.equals(criteria))
            {
                collCourseOfferingUnits = CourseOfferingUnitPeer.doSelectJoinUnit(criteria);
            }
        }
        lastCourseOfferingUnitsCriteria = criteria;

        return collCourseOfferingUnits;
    }
                            


                          
            
    /**
     * Collection to store aggregation of collClassrooms
     */
    protected List collClassrooms;

    /**
     * Temporary storage of collClassrooms to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initClassrooms()
    {
        if (collClassrooms == null)
        {
            collClassrooms = new ArrayList();
        }
    }

    /**
     * Method called to associate a Classroom object to this object
     * through the Classroom foreign key attribute
     *
     * @param l Classroom
     * @throws TorqueException
     */
    public void addClassroom(Classroom l) throws TorqueException
    {
        getClassrooms().add(l);
        l.setUnit((Unit) this);
    }

    /**
     * The criteria used to select the current contents of collClassrooms
     */
    private Criteria lastClassroomsCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getClassrooms(new Criteria())
     *
     * @throws TorqueException
     */
    public List getClassrooms() throws TorqueException
    {
        if (collClassrooms == null)
        {
            collClassrooms = getClassrooms(new Criteria(10));
        }
        return collClassrooms;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Unit has previously
     * been saved, it will retrieve related Classrooms from storage.
     * If this Unit is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getClassrooms(Criteria criteria) throws TorqueException
    {
        if (collClassrooms == null)
        {
            if (isNew())
            {
               collClassrooms = new ArrayList();
            }
            else
            {
                      criteria.add(ClassroomPeer.UNITID, getUnitid() );
                      collClassrooms = ClassroomPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(ClassroomPeer.UNITID, getUnitid());
                      if (!lastClassroomsCriteria.equals(criteria))
                {
                    collClassrooms = ClassroomPeer.doSelect(criteria);
                }
            }
        }
        lastClassroomsCriteria = criteria;

        return collClassrooms;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getClassrooms(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getClassrooms(Connection con) throws TorqueException
    {
        if (collClassrooms == null)
        {
            collClassrooms = getClassrooms(new Criteria(10), con);
        }
        return collClassrooms;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Unit has previously
     * been saved, it will retrieve related Classrooms from storage.
     * If this Unit is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getClassrooms(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collClassrooms == null)
        {
            if (isNew())
            {
               collClassrooms = new ArrayList();
            }
            else
            {
                       criteria.add(ClassroomPeer.UNITID, getUnitid());
                       collClassrooms = ClassroomPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(ClassroomPeer.UNITID, getUnitid());
                       if (!lastClassroomsCriteria.equals(criteria))
                 {
                     collClassrooms = ClassroomPeer.doSelect(criteria, con);
                 }
             }
         }
         lastClassroomsCriteria = criteria;

         return collClassrooms;
     }

                        
              
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Unit is new, it will return
     * an empty collection; or if this Unit has previously
     * been saved, it will retrieve related Classrooms from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Unit.
     */
    protected List getClassroomsJoinUnit(Criteria criteria)
        throws TorqueException
    {
        if (collClassrooms == null)
        {
            if (isNew())
            {
               collClassrooms = new ArrayList();
            }
            else
            {
                            criteria.add(ClassroomPeer.UNITID, getUnitid());
                            collClassrooms = ClassroomPeer.doSelectJoinUnit(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(ClassroomPeer.UNITID, getUnitid());
                        if (!lastClassroomsCriteria.equals(criteria))
            {
                collClassrooms = ClassroomPeer.doSelectJoinUnit(criteria);
            }
        }
        lastClassroomsCriteria = criteria;

        return collClassrooms;
    }
                  
                    
                    
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Unit is new, it will return
     * an empty collection; or if this Unit has previously
     * been saved, it will retrieve related Classrooms from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Unit.
     */
    protected List getClassroomsJoinClassroomArea(Criteria criteria)
        throws TorqueException
    {
        if (collClassrooms == null)
        {
            if (isNew())
            {
               collClassrooms = new ArrayList();
            }
            else
            {
                            criteria.add(ClassroomPeer.UNITID, getUnitid());
                            collClassrooms = ClassroomPeer.doSelectJoinClassroomArea(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(ClassroomPeer.UNITID, getUnitid());
                        if (!lastClassroomsCriteria.equals(criteria))
            {
                collClassrooms = ClassroomPeer.doSelectJoinClassroomArea(criteria);
            }
        }
        lastClassroomsCriteria = criteria;

        return collClassrooms;
    }
                            


                          
            
    /**
     * Collection to store aggregation of collEmployeeUnits
     */
    protected List collEmployeeUnits;

    /**
     * Temporary storage of collEmployeeUnits to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initEmployeeUnits()
    {
        if (collEmployeeUnits == null)
        {
            collEmployeeUnits = new ArrayList();
        }
    }

    /**
     * Method called to associate a EmployeeUnit object to this object
     * through the EmployeeUnit foreign key attribute
     *
     * @param l EmployeeUnit
     * @throws TorqueException
     */
    public void addEmployeeUnit(EmployeeUnit l) throws TorqueException
    {
        getEmployeeUnits().add(l);
        l.setUnit((Unit) this);
    }

    /**
     * The criteria used to select the current contents of collEmployeeUnits
     */
    private Criteria lastEmployeeUnitsCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getEmployeeUnits(new Criteria())
     *
     * @throws TorqueException
     */
    public List getEmployeeUnits() throws TorqueException
    {
        if (collEmployeeUnits == null)
        {
            collEmployeeUnits = getEmployeeUnits(new Criteria(10));
        }
        return collEmployeeUnits;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Unit has previously
     * been saved, it will retrieve related EmployeeUnits from storage.
     * If this Unit is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getEmployeeUnits(Criteria criteria) throws TorqueException
    {
        if (collEmployeeUnits == null)
        {
            if (isNew())
            {
               collEmployeeUnits = new ArrayList();
            }
            else
            {
                      criteria.add(EmployeeUnitPeer.UNITID, getUnitid() );
                      collEmployeeUnits = EmployeeUnitPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(EmployeeUnitPeer.UNITID, getUnitid());
                      if (!lastEmployeeUnitsCriteria.equals(criteria))
                {
                    collEmployeeUnits = EmployeeUnitPeer.doSelect(criteria);
                }
            }
        }
        lastEmployeeUnitsCriteria = criteria;

        return collEmployeeUnits;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getEmployeeUnits(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getEmployeeUnits(Connection con) throws TorqueException
    {
        if (collEmployeeUnits == null)
        {
            collEmployeeUnits = getEmployeeUnits(new Criteria(10), con);
        }
        return collEmployeeUnits;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Unit has previously
     * been saved, it will retrieve related EmployeeUnits from storage.
     * If this Unit is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getEmployeeUnits(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collEmployeeUnits == null)
        {
            if (isNew())
            {
               collEmployeeUnits = new ArrayList();
            }
            else
            {
                       criteria.add(EmployeeUnitPeer.UNITID, getUnitid());
                       collEmployeeUnits = EmployeeUnitPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(EmployeeUnitPeer.UNITID, getUnitid());
                       if (!lastEmployeeUnitsCriteria.equals(criteria))
                 {
                     collEmployeeUnits = EmployeeUnitPeer.doSelect(criteria, con);
                 }
             }
         }
         lastEmployeeUnitsCriteria = criteria;

         return collEmployeeUnits;
     }

                        
              
                    
                    
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Unit is new, it will return
     * an empty collection; or if this Unit has previously
     * been saved, it will retrieve related EmployeeUnits from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Unit.
     */
    protected List getEmployeeUnitsJoinEmployee(Criteria criteria)
        throws TorqueException
    {
        if (collEmployeeUnits == null)
        {
            if (isNew())
            {
               collEmployeeUnits = new ArrayList();
            }
            else
            {
                            criteria.add(EmployeeUnitPeer.UNITID, getUnitid());
                            collEmployeeUnits = EmployeeUnitPeer.doSelectJoinEmployee(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(EmployeeUnitPeer.UNITID, getUnitid());
                        if (!lastEmployeeUnitsCriteria.equals(criteria))
            {
                collEmployeeUnits = EmployeeUnitPeer.doSelectJoinEmployee(criteria);
            }
        }
        lastEmployeeUnitsCriteria = criteria;

        return collEmployeeUnits;
    }
                  
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Unit is new, it will return
     * an empty collection; or if this Unit has previously
     * been saved, it will retrieve related EmployeeUnits from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Unit.
     */
    protected List getEmployeeUnitsJoinUnit(Criteria criteria)
        throws TorqueException
    {
        if (collEmployeeUnits == null)
        {
            if (isNew())
            {
               collEmployeeUnits = new ArrayList();
            }
            else
            {
                            criteria.add(EmployeeUnitPeer.UNITID, getUnitid());
                            collEmployeeUnits = EmployeeUnitPeer.doSelectJoinUnit(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(EmployeeUnitPeer.UNITID, getUnitid());
                        if (!lastEmployeeUnitsCriteria.equals(criteria))
            {
                collEmployeeUnits = EmployeeUnitPeer.doSelectJoinUnit(criteria);
            }
        }
        lastEmployeeUnitsCriteria = criteria;

        return collEmployeeUnits;
    }
                            


          
    private static List fieldNames = null;

    /**
     * Generate a list of field names.
     *
     * @return a list of field names
     */
    public static synchronized List getFieldNames()
    {
        if (fieldNames == null)
        {
            fieldNames = new ArrayList();
              fieldNames.add("Unitid");
              fieldNames.add("Unitcode");
              fieldNames.add("Unitname");
              fieldNames.add("Unittype");
              fieldNames.add("Collegeid");
              fieldNames = Collections.unmodifiableList(fieldNames);
        }
        return fieldNames;
    }

    /**
     * Retrieves a field from the object by name passed in as a String.
     *
     * @param name field name
     * @return value
     */
    public Object getByName(String name)
    {
          if (name.equals("Unitid"))
        {
                return new Integer(getUnitid());
            }
          if (name.equals("Unitcode"))
        {
                return getUnitcode();
            }
          if (name.equals("Unitname"))
        {
                return getUnitname();
            }
          if (name.equals("Unittype"))
        {
                return getUnittype();
            }
          if (name.equals("Collegeid"))
        {
                return new Integer(getCollegeid());
            }
          return null;
    }
    
    /**
     * Retrieves a field from the object by name passed in
     * as a String.  The String must be one of the static
     * Strings defined in this Class' Peer.
     *
     * @param name peer name
     * @return value
     */
    public Object getByPeerName(String name)
    {
          if (name.equals(UnitPeer.UNITID))
        {
                return new Integer(getUnitid());
            }
          if (name.equals(UnitPeer.UNITCODE))
        {
                return getUnitcode();
            }
          if (name.equals(UnitPeer.UNITNAME))
        {
                return getUnitname();
            }
          if (name.equals(UnitPeer.UNITTYPE))
        {
                return getUnittype();
            }
          if (name.equals(UnitPeer.COLLEGEID))
        {
                return new Integer(getCollegeid());
            }
          return null;
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     *
     * @param pos position in xml schema
     * @return value
     */
    public Object getByPosition(int pos)
    {
            if (pos == 0)
        {
                return new Integer(getUnitid());
            }
              if (pos == 1)
        {
                return getUnitcode();
            }
              if (pos == 2)
        {
                return getUnitname();
            }
              if (pos == 3)
        {
                return getUnittype();
            }
              if (pos == 4)
        {
                return new Integer(getCollegeid());
            }
              return null;
    }
     
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     *
     * @throws Exception
     */
    public void save() throws Exception
    {
          save(UnitPeer.getMapBuilder()
                .getDatabaseMap().getName());
      }

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
       * Note: this code is here because the method body is
     * auto-generated conditionally and therefore needs to be
     * in this file instead of in the super class, BaseObject.
       *
     * @param dbName
     * @throws TorqueException
     */
    public void save(String dbName) throws TorqueException
    {
        Connection con = null;
          try
        {
            con = Transaction.begin(dbName);
            save(con);
            Transaction.commit(con);
        }
        catch(TorqueException e)
        {
            Transaction.safeRollback(con);
            throw e;
        }
      }

      /** flag to prevent endless save loop, if this object is referenced
        by another object which falls in this transaction. */
    private boolean alreadyInSave = false;
      /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally
     *
     * @param con
     * @throws TorqueException
     */
    public void save(Connection con) throws TorqueException
    {
          if (!alreadyInSave)
        {
            alreadyInSave = true;


  
            // If this object has been modified, then save it to the database.
            if (isModified())
            {
                if (isNew())
                {
                    UnitPeer.doInsert((Unit) this, con);
                    setNew(false);
                }
                else
                {
                    UnitPeer.doUpdate((Unit) this, con);
                }
            }

                                      
                
            if (collDegreeCourses != null)
            {
                for (int i = 0; i < collDegreeCourses.size(); i++)
                {
                    ((DegreeCourse) collDegreeCourses.get(i)).save(con);
                }
            }
                                          
                
            if (collDegreeCurriculums != null)
            {
                for (int i = 0; i < collDegreeCurriculums.size(); i++)
                {
                    ((DegreeCurriculum) collDegreeCurriculums.get(i)).save(con);
                }
            }
                                          
                
            if (collCourseOfferingUnits != null)
            {
                for (int i = 0; i < collCourseOfferingUnits.size(); i++)
                {
                    ((CourseOfferingUnit) collCourseOfferingUnits.get(i)).save(con);
                }
            }
                                          
                
            if (collClassrooms != null)
            {
                for (int i = 0; i < collClassrooms.size(); i++)
                {
                    ((Classroom) collClassrooms.get(i)).save(con);
                }
            }
                                          
                
            if (collEmployeeUnits != null)
            {
                for (int i = 0; i < collEmployeeUnits.size(); i++)
                {
                    ((EmployeeUnit) collEmployeeUnits.get(i)).save(con);
                }
            }
                          alreadyInSave = false;
        }
      }


                          
      /**
     * Set the PrimaryKey using ObjectKey.
     *
     * @param  unitid ObjectKey
     */
    public void setPrimaryKey(ObjectKey key)
        throws TorqueException
    {
            setUnitid(((NumberKey) key).intValue());
        }

    /**
     * Set the PrimaryKey using a String.
     *
     * @param key
     */
    public void setPrimaryKey(String key) throws TorqueException
    {
            setUnitid(Integer.parseInt(key));
        }

  
    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
          return SimpleKey.keyFor(getUnitid());
      }

 

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
       * It then fills all the association collections and sets the
     * related objects to isNew=true.
       */
      public Unit copy() throws TorqueException
    {
        return copyInto(new Unit());
    }
  
    protected Unit copyInto(Unit copyObj) throws TorqueException
    {
          copyObj.setUnitid(unitid);
          copyObj.setUnitcode(unitcode);
          copyObj.setUnitname(unitname);
          copyObj.setUnittype(unittype);
          copyObj.setCollegeid(collegeid);
  
                    copyObj.setUnitid(0);
                                    
                                      
                
        List v = getDegreeCourses();
        for (int i = 0; i < v.size(); i++)
        {
            DegreeCourse obj = (DegreeCourse) v.get(i);
            copyObj.addDegreeCourse(obj.copy());
        }
                                                  
                
        v = getDegreeCurriculums();
        for (int i = 0; i < v.size(); i++)
        {
            DegreeCurriculum obj = (DegreeCurriculum) v.get(i);
            copyObj.addDegreeCurriculum(obj.copy());
        }
                                                  
                
        v = getCourseOfferingUnits();
        for (int i = 0; i < v.size(); i++)
        {
            CourseOfferingUnit obj = (CourseOfferingUnit) v.get(i);
            copyObj.addCourseOfferingUnit(obj.copy());
        }
                                                  
                
        v = getClassrooms();
        for (int i = 0; i < v.size(); i++)
        {
            Classroom obj = (Classroom) v.get(i);
            copyObj.addClassroom(obj.copy());
        }
                                                  
                
        v = getEmployeeUnits();
        for (int i = 0; i < v.size(); i++)
        {
            EmployeeUnit obj = (EmployeeUnit) v.get(i);
            copyObj.addEmployeeUnit(obj.copy());
        }
                    
        return copyObj;
    }

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public UnitPeer getPeer()
    {
        return peer;
    }

    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append("Unit:\n");
        str.append("Unitid = ")
           .append(getUnitid())
           .append("\n");
        str.append("Unitcode = ")
           .append(getUnitcode())
           .append("\n");
        str.append("Unitname = ")
           .append(getUnitname())
           .append("\n");
        str.append("Unittype = ")
           .append(getUnittype())
           .append("\n");
        str.append("Collegeid = ")
           .append(getCollegeid())
           .append("\n");
        return(str.toString());
    }
}
